package com.foreknow.demo5;

import java.util.Scanner;

public class Employee1 {
    public void game(){
        String opponent = "刘备";//默认刘备
        String anwser = "y";
        System.out.println("————————————欢 迎 进 入 游 戏 世 界————————————");
        System.out.println("             *********************            ");
        System.out.println("             **    猜拳，开始   **");
        System.out.println("             *********************            ");
        System.out.println("出拳规则：1.剪刀\t2.石头\t3.布");
        System.out.print("请输入你的姓名:");
        Scanner input = new Scanner(System.in);
        String name = input.next();//用户名不变
        do {
            int x = 0;
            int y = 0;
            int z = 0;
            System.out.print("请选择对方角色（1.刘备\t2.孙权\t3.曹操）:");
            int i = input.nextInt();
            switch (i){
                case 1:
                    opponent = "刘备";
                    break;
                case 2:
                    opponent = "孙权";
                    break;
                case 3:
                    opponent = "曹操";
                    break;
                default:
                    System.out.println("选择错误，暂无次角色！");
                    continue;//重新选择
            }
            System.out.println(name  + "\tVS\t"  + opponent + "\t准备开始！");
            System.out.println("要开始吗？(y/n)");
            anwser = input.next();
            do {
                System.out.print("请出拳：1.剪刀\t2.石头\t3.布（输入相应数字）:");
                int j = input.nextInt();
                int m = (int)(Math.random()*3+1);
                switch (j){
                    case 1:
                        if (m == 1){
                            System.out.println("你出拳：剪刀");
                            System.out.println(opponent + "出拳：剪刀");
                            System.out.println("结果：平局！");
                            z++;
                        }
                        if (m == 2){
                            System.out.println("你出拳：剪刀");
                            System.out.println(opponent + "出拳：石头");
                            System.out.println("结果：◞‸◟ ，你输了，加油哦！");
                            y++;
                        }
                        if (m == 3){
                            System.out.println("你出拳：剪刀");
                            System.out.println(opponent + "出拳：布");
                            System.out.println("结果：恭喜，你赢了！");
                            x++;
                        }
                        break;
                    case 2:
                        if (m == 1){
                            System.out.println("你出拳：石头");
                            System.out.println(opponent + "出拳：剪刀");
                            System.out.println("结果：恭喜，你赢了！");
                            x++;
                        }
                        if (m == 2){
                            System.out.println("你出拳：石头");
                            System.out.println(opponent + "出拳：石头");
                            System.out.println("结果：平局！");
                            z++;
                        }
                        if (m == 3){
                            System.out.println("你出拳：石头");
                            System.out.println(opponent + "出拳：布");
                            System.out.println("结果：◞‸◟ ，你输了，加油哦！");
                            y++;
                        }
                        break;
                    case 3:
                        if (m == 1){
                            System.out.println("你出拳：布");
                            System.out.println(opponent + "出拳：剪刀");
                            System.out.println("结果：◞‸◟ ，你输了，加油哦！");
                            y++;
                        }
                        if (m == 2){
                            System.out.println("你出拳：布");
                            System.out.println(opponent + "出拳：石头");
                            System.out.println("结果：恭喜，你赢了！");
                            x++;
                        }
                        if (m == 3){
                            System.out.println("你出拳：布");
                            System.out.println(opponent + "出拳：布");
                            System.out.println("结果：平局！");
                            z++;
                        }
                        break;
                    default:
                        System.out.println("输入错误！");
                        continue;
                }
                System.out.print("是否开始下一轮(y/n):");
                anwser = input.next();
                System.out.println("---------------------------------------");
            }while ("y".equals(anwser));
            System.out.println(name  + "\tVS\t"  + opponent);
            System.out.println("对战次数：" +(x+y+z));
            System.out.println("\n姓名\t得分");
            System.out.println(name+"\t"+x);
            System.out.println(opponent+"\t"+y);
            System.out.println("平局\t"+z);
            if (x > y){
                System.out.println("\n恭喜你获得本局胜利！\n");
            }
            if (x < y){
                System.out.println("\n本局你失败了！\n");
            }
            if (x == y){
                System.out.println("\n本局平局！无获胜者！\n");
            }
            System.out.print("要开始下一局吗？(y/n):");
            anwser = input.next();
        }while ("y".equals(anwser));
    }
    public static void main(String[] args) {
        Employee1 employee1 = new Employee1();
        employee1.game();
    }
}
